import numpy as np
import pandas as pd
from sklearn.preprocessing import StandardScaler
import tensorflow as tf
from joblib import load

class NN(object):
    def __init__(self):
        self.df = pd.read_csv('./NN/scenic_data.csv')
        self.laoded_model = tf.keras.model.load_model('NN/my_model.keras')
        self.scaler = load('NN/scaler.joblib')
        
    def get_hourly_trend(self):
        """获取预测结果
        """
        
        n_steps = 7
        latest_data = self.df.iloc[-n_steps:].values #取最后七天的数据
        latest_data = latest_data.reshape(1,n_steps,latest_data.shape[1])
        
        #预测与反归一化
        predicted = self.laoded_model.predict(latest_data)
        predicted_count = self.scaler.inverse_transform(predicted)
        predicted_count[predicted_count < 0] = 0
        
        hourly_trend = predicted_count[0].astype(int).tolist()
        print(hourly_trend)
if __name__ == '__main__':
    nn = NN()
    nn.get_hourly_trend()
